// /////////////////////////////////////////////////////////////////////////////
//
// Name:            AboutFrame.cpp
// Author:          Michael Bartsch
//
// Desc :           This file contains the CAboutFrame Class. This class
//                  contains the About frame which displays about information.
//
// License:         Copyright (C) 2008-2009 Michael Bartsch
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the GNU General Public
//                  License as published by the Free Software Foundation,
//                  either version 3 of the License, or (at your option) any
//                  later version.
//
//                  This program is distributed in the hope that it will be
//                  useful, but WITHOUT ANY WARRANTY; without even the implied
//                  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//                  PURPOSE. See the GNU General Public License for more
//                  details.
//
//                  You should have received a copy of the GNU General Public
//                  License along with this program. If not, see
//                  <http://www.gnu.org/licenses/>.
//
// /////////////////////////////////////////////////////////////////////////////

// Include required header file(s).
#include "AboutFrame.h"


// CAboutFrame Events. - [ BEGIN ]
BEGIN_EVENT_TABLE(CAboutFrame, wxFrame)
   EVT_CLOSE(CAboutFrame::onClose)
END_EVENT_TABLE()
// CAboutFrame Events. - [ END ]


// CAboutFrame.
// Constructor.
CAboutFrame::CAboutFrame(wxWindow *parent)
: wxFrame(parent, wxID_ANY, _T("Aia|CP - About"), wxPoint(0,0), wxSize(500,630), wxDEFAULT_FRAME_STYLE & ~ (wxRESIZE_BORDER | wxRESIZE_BOX | wxMAXIMIZE_BOX))
{
    // Set internal variables.
    frameParent = (CMainFrame*)parent;

    // Main sizer.
    wxPanel *mainPanel = new wxPanel(this, -1, wxDefaultPosition, wxSize(500, 630));
    wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);

    // Bitmap.
    wxBitmap *aboutBitmap = new wxBitmap("../media/splash.png", wxBITMAP_TYPE_PNG);
    wxStaticBitmap *aboutControl = new wxStaticBitmap(mainPanel, wxID_ANY, *aboutBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN);

    mainSizer->Add(aboutControl, wxSizerFlags().Expand().Border(wxTOP | wxBOTTOM, 2));

    // Book
    wxNotebook *aboutBook = new wxNotebook(mainPanel, wxID_ANY, wxDefaultPosition, wxSize(500, 300));

    // Book - Thanks page.
    FILE *file;
    int fileSize;

    wxTextCtrl *thanksPage = new wxTextCtrl(aboutBook, wxID_ANY, _T(""), wxDefaultPosition, wxSize(500, 300), wxTE_MULTILINE | wxTE_READONLY | wxALWAYS_SHOW_SB | wxVSCROLL);

    file = fopen("../CREDITS", "r");

    if(file != NULL)
    {
       // Get file size.
       fseek (file, 0, SEEK_END);
       fileSize = ftell(file);
       rewind(file);

       // Create the buffer.
       char *buffer = new char[fileSize];
       fread (buffer, 1, fileSize, file);

       // Add to the text control.
       thanksPage->AppendText(buffer);
       thanksPage->ShowPosition(0);

       // Close the file and empty the buffer.
       fclose(file);
       delete[] buffer;
    }

    aboutBook->AddPage(thanksPage, _T("Thanks to..."), false);

    // License page.
    wxTextCtrl *licensePage = new wxTextCtrl(aboutBook, wxID_ANY, _T(""), wxDefaultPosition, wxSize(500, 300), wxTE_MULTILINE | wxTE_READONLY | wxALWAYS_SHOW_SB | wxVSCROLL);

    file = fopen("../COPYING", "r");

    if(file != NULL)
    {
       // Get file size.
       fseek (file, 0, SEEK_END);
       fileSize = ftell(file);
       rewind(file);

       // Create the buffer.
       char *buffer = new char[fileSize];
       fread (buffer, 1, fileSize, file);

       // Add to the text control.
       licensePage->AppendText(buffer);
       licensePage->ShowPosition(0);

       // Close the file and empty the buffer.
       fclose(file);
       delete[] buffer;
    }

    aboutBook->AddPage(licensePage, _T("License"), false);

    mainSizer->Add(aboutBook, wxSizerFlags().Expand().Border(wxTOP | wxBOTTOM, 2));

    // Set the main sizer.
    mainPanel->SetSizer(mainSizer);
    mainSizer->SetSizeHints(mainPanel);
}

// Event Functions. - [ BEGIN ]
void CAboutFrame::onClose(wxCloseEvent &event)
{
    // Reset frame state.
    MakeModal(false);

    // Destroy frame.
    Destroy();
}
// Event Functions. - [ END ]

// End of File
